package com.hxzy.controller.anonymous.merchandiser;

import com.github.pagehelper.PageInfo;
import com.hxzy.common.controller.BaseController;
import com.hxzy.common.enums.AckCode;
import com.hxzy.common.resp.R;
import com.hxzy.controller.anonymous.merchandiser.req.AnonyMerchandiserInfoReq;
import com.hxzy.controller.anonymous.merchandiser.req.AnonyMerchandiserSearchReq;
import com.hxzy.controller.anonymous.merchandiser.req.MerchandiserAddReq;
import com.hxzy.controller.anonymous.merchandiser.resp.AnonyMerchandiserResp;
import com.hxzy.service.MerchandiserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

@RestController
@RequestMapping(value = "/anony/merchandiser")
@Api(tags = "匿名-商户Api")
public class AnonyMerchandiserController extends BaseController {


    @Autowired
    private MerchandiserService merchandiserService;


    @ApiOperation(value = "商户注册")
    @PostMapping(value = "/register")
    public R register(@RequestBody @Valid MerchandiserAddReq req){
        boolean result=this.merchandiserService.register(req);
        return result?R.ok(): R.build(AckCode.DATABASE_ERROR);
    }


    @ApiOperation(value = "获取距离我8公里之内的商家")
    @GetMapping(value = "/data")
    public R<PageInfo<AnonyMerchandiserResp>> search(@Valid AnonyMerchandiserSearchReq req){
        super.startPage(req);

        List<AnonyMerchandiserResp> list= this.merchandiserService.anonySearch(req);

        return super.buildPageInfo(list);
    }



    //anony/merchandiser/findById?longitude=106.472296&latitude=29.632273&merchantId=9

    @ApiOperation(value = "查询商家信息")
    @GetMapping(value = "/findById")
    public R<AnonyMerchandiserResp>  findByInfo(@Valid AnonyMerchandiserInfoReq req){
        AnonyMerchandiserResp resp= this.merchandiserService.findByInfo(req);
        return R.okHasData(resp);
    }
}
